/**************************************************************************
 * @doc CORE
 * @module Table.C |
 * Source code for handling the Function table Flexi record and the function
 * array.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :
 * <nl>Notes       :
 *
 * @head3 Core Functions |
 * @index | Core
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 $Log: /SoftPay/SPK2SIM/Source/Tran/table.c $
 ********************************************************************************/


#define VSTABLE_C
#include <dbmgr.h>
#include <acldev.h>
#include <string.h>
#include <varrec.h>

#include <project.h>

/** /#define DEBUG_VSTABLE*/
#ifdef DEBUG_VSTABLE
#define DEBUG_95
#endif


#include <define.h>
#include <validt.h>
#include <cdt.h>
#include <funcids.h>
#include <table.h>
#include <accum.h>
#include <comm.h>
#include <report.h>
#include <review.h>
#include <msg.h>
#include <msgfuncs.h>
#include <transact.h>
#include <card.h>
#include <clerk.h>
#include <fields.h>
#include <tip.h>
#include <pcheck.h>
#include <pbatch.h>
#include <logo.h>
#include <ui.h>
#include <mem.h>
#include <util.h>
#include <date.h>
#include <ztconf.h>
#include <appl.h>
#include <init.h>
#include <test.h>
#include <operate.h>
#include <opedit.h>
#include <report.h>
#include <fct.h>
#include <print.h>
#include <pcheck.h>
#include <settle.h>
#include <stats.h>
#include <settlbat.h>
#include <merch.h>
#include <modem.h>
#include <rptmerch.h>
#include <vidnld.h>
#include <paramrpt.h>
#include <passwd.h>
#include <piputl.h>
#include <mdlfuncs.h>
#include <spdebug.h>
#include <msngr.h>
#include <mbtx3.h>
#ifdef MOBITEX_DEFINED
#include <mbtx.h>
#endif
#include <menufunc.h>
#include <tmadef.h>
#ifdef EMV_MOUDLE
#include <emvfuncs.h>
#endif
#ifdef VXEMVAPP
/* No include need in this file at this moment */
/* #include <vxemvap.h> */
/*  It seems that we don't need the following functions in EMV 4.0
extern int inEMVPrepareBatchFlow(TRANSACTION_OBJECT *pobTran);
extern int inEMVCardholderVerificationEnvelope(TRANSACTION_OBJECT *pobTran);
extern int inEMVResetPCT(TRANSACTION_OBJECT *pobTran);
*/
#endif
#include <FuncComms.h>


char szMsgFileName[] = "msg";
char szAccFileName[] = "acc";
char szSpaFileName[] = "spa";
char szMdmFileName[] = "mdm";
char szClkFileName[] = "clk";
char szLoyFileName[] = "loy";
char szCardFileName[] = "card";
char szDulFileName[] = "dul";
char szShfFileName[] = "shf";
char szBatFileName[] = "bat";
char szPmtFileName[] = "pmt";
char szISO8583FileName[] = "isor";
char szISO8583EngFileName[] = "isoe";
char szCntFileName[] = "cont";
char szEmvFileName[] = "emv";
char szMsngFileName[] = "msng";
char szFltFileName[] = "flt";
char szMbtxFileName[] = "mbtx";

extern int inBuildAndSendPacket(TRANSACTION_OBJECT* pobTran);


FUNCTION_TABLE srTransactionGeneralFuncs[] = {
    #ifndef REMOVE_CORE_GET_BASE_AMOUNT
    {inGetBaseAmount,                       GET_BASE_AMOUNT},
    #endif /*#ifndef REMOVE_CORE_GET_BASE_AMOUNT */


    #ifndef REMOVE_CORE_GET_CASH_BACK
    {inGetCashBack,                         GET_CASH_BACK},
    #endif /*#ifndef REMOVE_CORE_GET_CASH_BACK */


    #ifndef REMOVE_CORE_COMPUTE_DISPLAY_TOTAL
    {inComputeAndDispTotal,                 COMPUTE_DISPLAY_TOTAL},
    #endif /* #ifndefREMOVE_CORE_COMPUTE_DISPLAY_TOTAL */


    {inGetAuthCode,                         GET_AUTH_CODE},
    {inGetLastFourAcct,                     GET_LAST_FOUR_ACCT},
    #ifndef REMOVE_CORE_GET_ADJUST_AMOUNT
    {inGetAdjustAmount,                     GET_ADJUST_AMOUNT},
    #endif /*#ifndef REMOVE_CORE_GET_ADJUST_AMOUNT */


    #ifndef REMOVE_CORE_GET_CONFIRMATION
    {inGetConfirmation,                     GET_CONFIRMATION},
    #endif /*#ifndef REMOVE_CORE_GET_CONFIRMATION */


    {inBuildAndSendPacket,                  BUILD_AND_SEND_PACKET},
    {inAVS,                                 AVS},
    #ifndef REMOVE_CORE_DEBIT_PREDIAL
    {inDebitPredial,                        DEBIT_PREDIAL},
    #endif /*#ifndef REMOVE_CORE_DEBIT_PREDIAL */

    #ifndef REMOVE_CORE_GET_ROOM_NUMBER
    {inGetRoomNumber,                       GET_ROOM_NUMBER},
    #endif
    {inGetInvNum,                           GET_INV_NUM},
    {inUpdateTermInvAndHostInv,             UPDATE_TERM_INV_AND_HOST_INV},
    {inChkMustSettleFlag,                   CHK_MUST_SETTLE_FLAG},
    #ifndef REMOVE_CORE_GET_CLOSE_TAB_AMOUNT
    {inGetCloseTabAmount,                   GET_CLOSE_TAB_AMOUNT},
    #endif
    #ifndef REMOVE_CORE_GET_ORIG_TRANS_DATE
    {inGetOrigTransDate,                    GET_ORIG_TRANS_DATE},
    #endif /* #ifndef REMOVE_CORE_GET_ORIG_TRANS_DATE */


    {inGetCustNumber,                       GET_CUST_NUMBER},
    {inCreditPredial,                       CREDIT_PREDIAL},
    #ifndef REMOVE_CORE_DUPLICATE_CHECK    
    {inDupCheck,                            DUPLICATE_CHECK},
    #endif /*     #ifndef REMOVE_CORE_DUPLICATE_CHECK     */


    {inScrollOff,                           SCROLL_OFF},
    {inScrollOn,                            SCROLL_ON},
    {inGetReceiptTemplate,                  GET_RECEIPT_TEMPLATE},
    #ifndef  REMOVE_CORE_GET_TAX
    {inGetTax,                              GET_TAX},
    #endif /*   #ifndef  REMOVE_CORE_GET_TAX */

    {inGetTip,                              GET_TIP},
    #ifndef  REMOVE_CORE_COUNTER_PAY_TIP
    {inGetCounterPayTip,                    COUNTER_PAY_TIP},
    #endif /* #ifedif REMOVE_CORE_COUNTER_PAY_TIP */

    #ifndef REMOVE_CORE_GET_WEB_MENU
    {inGetWebMenu,                           GET_WEB_MENU},
    #endif /* #ifndef REMOVE_CORE_GET_WEB_MENU */


    {inScrollNextLineOn,                    SCROLL_NEXTLINE},
    #ifndef  REMOVE_CORE_GET_CVV2
    {inGetCVV2,                             GET_CVV2},
    #endif /* #ifndef  REMOVE_CORE_GET_CVV2 */
    #ifndef  REMOVE_CORE_FPS_RESP_MESSAGE
    {inFPSRespMessage,                      FPS_RESP_MESSAGE},
    #endif /* REMOVE_CORE_FPS_RESP_MESSAGE */

    {inDisplayResponse,                     DISPLAY_RESPONSE},
    {inValidateDockStatus,                  VALIDATE_DOCK_STATUS},
 
    #ifdef EMV_MODULE
    {inEMVPrepareBatchFlow,                 EMV_BATCH_FLOW},
    {inEMVCardholderVerificationEnvelope,   EMV_CARD_VERIF_ENVELOPE},
    {inEMVResetPCT,                         EMV_RESET_PCT},
    #endif  

   #ifdef TMA_DEFINED
    {inTransactionDetail,                   TRANSACTION_DETAIL},
    {inStartTransTimer,                     START_TRANS_TIMER},
    #endif

	#ifdef VXEMVAPP
	/*** It seems that we don't need this in EMV 4.0
	    {inEMVPrepareBatchFlow,                 EMV_BATCH_FLOW},
	    {inEMVCardholderVerificationEnvelope,   EMV_CARD_VERIF_ENVELOPE},
	    {inEMVResetPCT,                         EMV_RESET_PCT},
	*/
	#endif

    {0,                                     END_OF_FUNC_TABLE},

};

const FUNCTION_TABLE srOperationGeneralFuncs[] = {
    {inNotAvailableOperation,               NOT_AVAILABLE},
    {inGetHostNum,                          GET_HOST_NUM},
    {inSelectAndLoadHost,                   SELECT_AND_LOAD_HOST},
    {inGetInvoiceNumber,                    GET_INVOICE_NUMBER},
    {inGetSettAll,                          GET_SETT_ALL},
    {inGetBatchNumber,                      GET_BATCH_NUM},
    {inGetSettDate,                         GET_SETT_DATE},
    {inCheckSettleFlag,                     CHK_SETTLE_FLAG},
    {inGetCurrency,                         GET_CURRENCY},
    /*    {inQADebugReportOperation,              PRINT_PARAMETERS_REPORT}, CALLED TWICE  */

    {inDisplayAtInit,                       DISPLAY_AT_INIT},
    {inInitCOMM_OBJECT,                     INIT_COMM_OBJECT},
    {inInitConfigRecs,                      INIT_CONFIG_RECS},
    #ifdef ZTEXPRESS_DEFINED
    {inInitExpressConfig,                   INIT_EXPRESS_CONFIG},
    #else  
    {inNotAvailableOperation,               INIT_EXPRESS_CONFIG},
    #endif
    {inInitTerminalBeep,                    INIT_TERMINAL_BEEP},
    {inTestTables,                          TEST_TABLES},
    {inInitPrintandForm,                    INIT_PRINT_FORM},
    {inC3IN_Functionality,                  C3IN_FUNCTIONALITY},
    {inMemoryCheck,                         MEMORY_CHECK},
    {inAutoSettle,                          INIT_AUTO_SETTLE},
    {inDisplayAtIdle,                       DISPLAY_AT_IDLE},
    {inHourlyNotify,                        HOURLY_NOTIFY},
    {inMultiApp,                            MULTI_APP},
    {inAutoAnswerInit,                      INIT_AUTO_ANSWER},
    {inDateTimeOperation,                   GET_DATE_TIME},
    {inAboutFileProcessing,                 ABOUT_FILE_PROCESSING},
    {inFullDownloadOperation,               FULL_DOWNLOAD},
    {inEditCDTOperation,                    EDIT_CDT},
    {inEditCPTOperation,                    EDIT_CPT},
    {inEditDPTOperation,                    EDIT_DPT},
    {inEditFCTOperation,                    EDIT_FCT},
    {inProcessFCT,                          PROCESS_FCT},
    {inEditHDTOperation,                    EDIT_HDT},
    {inEditLDTOperation,                    EDIT_LDT},
    {inEditTCTOperation,                    EDIT_TCT},
    {inEditHFTOperation,                    EDIT_HOST_TABLES},
    {inEditBDTOperation,                    EDIT_BDT},
    {inPartDownloadOperation,               PARTIAL_DOWNLOAD},
    {inEditCCTOperation,                    EDIT_CCT},
    {inEditICTOperation,                    EDIT_ICT},
    {inQADebugReportOperation,              PARAMETERS_REPORT},
    {inLangSetOperation,                    LANGUAGE_SET},
    {inStatReportOperation,                 PRINT_STATS_REPORT},
    {inLockOperation,                       LOCK_KEYBOARD},
    {inDemoTrainOperation,                  TRAINING_MODE},
    {inSetCloseTabSameCardFlag,             SET_CLOSE_TAB_FLAG},
    {inVeritalkDownload,                    VERITALK_DOWNLOAD},
    {inEditMITOperation,                    EDIT_MIT},
    {inEditMHTOperation,                    EDIT_MHT},
    #ifndef  REMOVE_CORE_GET_CHECK_MID
    {inGetCheckMID,                         GET_CHECK_MID},
    #endif /* #ifndef  REMOVE_CORE_GET_CHECK_MID */

    #ifdef PARAMRPT_C
    {inParameterReportOperation,            PRINT_PARAM_REPORT},
    #endif /* PARAMRPT_C */
    {inMerchTableReportOperation,           PRINT_MERCH_REPORT},
    // {inSelectOneAllMID,                     SELECT_ONEALL_MID},
    //    This is not called as an ID , but as function call , there is no need to have ID

    {inEditPCTOperation,                    EDIT_PCT},
    {inEditPMTOperation,                    EDIT_PMT},
    {inEditCRTOperation,                    EDIT_CRT},
    {inEditTables,                          EDIT_TABLES},
    {inColdInitPinpad,                      COLD_INIT_PINPAD},
    {inCheckMultiCurrency,                  CHECK_MULTI_CURRENCY},
    {inEditIITOperation,                    EDIT_IIT},
    {inEditISTOperation,                    EDIT_IST},
    #ifdef COUNTER_DEFINED
    {inEditCNTOperation,                    EDIT_CNT},
    #endif/*COUNTER_DEFINED*/
    {inEditPITOperation,                    EDIT_PIT},
    #ifdef MESSENGER_DEFINED
    {inRequestMail,                         REQUEST_MAIL},
    {inShowNewMail,                         SHOW_NEW_MAIL},
    {inShowNewHelp,                         SHOW_NEW_HELP},
    {inSettleRequestMailFlow,               SETTLE_REQUEST_MAIL},
    #endif
    #ifdef FLEET_DEFINED
    {inEditPDTOperation,                    EDIT_PDT},
    #endif  
    #ifdef EMV_MODULE
    {inEditMVTOperation,                    EDIT_MVT},
    #endif  
#ifdef VXEMVAPP
	{inEditESTOperation,					EDIT_EST},
	{inEditMVTOperation,					EDIT_MVT},
#endif	
    {inColdInitRadioModem,                  INIT_RADIO_MODEM},
    #ifdef MOBITEX_DEFINED
    {inSignalStrengthOperation,             SIGNAL_STRENGTH},
    {inEditMCTOperation,                    EDIT_MCT},
    #endif
	{inEditAATOperation,                    EDIT_AAT},
    {inPrintFormFeedsOperation,             PRINT_FORMFEEDS},
    {inHostInitiatedDownload,               HOST_INITIATED_DOWNLOAD},
    {0,                                     END_OF_FUNC_TABLE},

};

FUNCTION_TABLE srValidationFuncs[] = {
    {inRange_0TO2,                          RANGE_0TO2},
    {inRange_0TO59,                         RANGE_0TO59},
    {inTimeVal,                             TIME_VAL},
    {inBeepVal,                             BEEP_VAL},
    {inP350ColModeVal,                      P350_COL_MODE_VAL},
    {inCkrdrPortVal,                        CKRDR_TYPE_VAL},
    {inBaudRtVal,                           BAUD_VAL},
    {inPortFmtVal,                          PORTFMT_VAL},
    {inBitVal,                              BIT_0OR1},
    {inMKeyVal,                             MKEY_VAL},
    {inCommLinkVal,                         LINK_VAL},
    {inRange_0TO3,                          RANGE_0TO3},
    {inRange_0TO1,                          RANGE_0TO1},
    {inRange_0TO4,                          RANGE_0TO4},
    {inRange_0TOCST,                        RANGE_0TOCST},
    {inRange_0TOLCT,                        RANGE_0TOLCT},
    {inPrintOptionVal,                      PRINT_OPTION},
    {inCardTypeVal,                         CARD_TYPE},
    {inAutoAnswerVal,                       AUTO_ANS_VAL},
    {inCheckEntryModeVal,                   ENTRY_MODE_VAL},
    {inRange_1TO3,                          RANGE_1TO3},
    {inBatchNumVal,                         BATCH_VAL},
    {inNumRingsVal,                         NUM_OF_RINGS_VAL},
    {inShortVal,                            SHORT_VAL},
    {inLongVal,                             LONG_VAL},
    {inRange_0TO5,                          RANGE_0TO5},
    {inP350LPIVal,                          P350_LPI_VAL},
    {inMANVal,                              MAN_TYPE_VAL},
    {inRSSIVal,                             RSSI_TYPE_VAL},
    {inAATVal,                              AAT_VAL},
    {inAATFmtVal,                           AAT_FMT_VAL},
    {inNumStrVal,                           NUM_STR_VAL},
    {inOpenTAmtVal,                         OPEN_TAMT_VAL},
    {0,                                     END_OF_FUNC_TABLE},

};

/*
 *      OVERLOADABLE FUNCTIONS
 */

const FUNCTION_TABLE srOverLoadFuncs[] = {
    {inDefaultDisplayReviewRec,             DISPLAY_REVIEW_REC},
    {(PFI_TO) inDefaultAccessFunction,              CUSTOM_ACCESS_FUNCTION},
    {inDefaultDemoFunction,                 DEMO_FUNCTION},
    {inDefaultCustomCommInit,               CUSTOM_COMM_INIT},
    {inDefaultFPSQualifierFunction,         FPS_QUALIFIER_FUNCTION},
    {(PFI_TO) inDefaultSetModemObjectFunctions,     SET_MODEM_OBJECT},
    {(PFI_TO) inDefaultGetMenusFileName,                GET_MENU_FILE_NAME},
    {NULL_PFI,                              CUSTOM_ERROR_FUNCTION},
    {0,                                     END_OF_FUNC_TABLE},

};


MSG_FILE_NAME_TABLE srMsgFileNameTable[] = {
    {szMsgFileName,         MSG_NAME_ID},
    {szAccFileName,         ACC_NAME_ID},
    {szSpaFileName,         SPA_NAME_ID},
    {szMdmFileName,         MDM_NAME_ID},
    {szClkFileName,         CLK_NAME_ID},
    {szLoyFileName,         LOY_NAME_ID},
    {szCardFileName,        CARD_NAME_ID},
    {szDulFileName,         DUL_NAME_ID},
    {szShfFileName,         SFT_NAME_ID},
    {szBatFileName,         BAT_NAME_ID},
    {szPmtFileName,         PMT_NAME_ID},
    {szISO8583FileName,     ISO8583_NAME_ID},
    {szISO8583EngFileName,  ISO8583ENG_NAME_ID},
    {szCntFileName,         CNT_NAME_ID},
    {szEmvFileName,         EMV_NAME_ID},
    {szMsngFileName,        MSNGR_NAME_ID},
    {szFltFileName,         FLT_NAME_ID},
    #ifdef MOBITEX_DEFINED
    {szMbtxFileName,        MBTX_NAME_ID},
    #endif

    {0,             END_OF_FUNC_TABLE},

};

/* The flexi record used for the function table */
unsigned char* gpsrFunctionRecord;


/*********************************************************************************************
* @func int | inInitializeFunctionRecord |
*       Creates the flexi record for the function table
*
* @rdesc return values.
* @flag int    |  VS_ERR, VS_ESCAPE or VS_SUCCESS
* @end
**********************************************************************************************/

int inInitializeFunctionRecord() {
    PFI pinFunc;
    int inCount = 0;
    int inFLXRSZ = get_env_int("FUNRSZ");
    int inMaxFlexiRecSize;

    /*
     *      Function Flexi Record size if configurable via CONFIG.SYS variable above
     */
    inMaxFlexiRecSize = (inFLXRSZ < MIN_FLEXI_REC_SIZE ? MIN_FLEXI_REC_SIZE : inFLXRSZ);
    pdebug(("inMaxFlexiRecSize=%d", inMaxFlexiRecSize));
    if ((gpsrFunctionRecord = (unsigned char *) pchAlloc(inMaxFlexiRecSize)) == NULL_CH)
        return (VS_ERR);

    vVarInitRecord(gpsrFunctionRecord, inMaxFlexiRecSize, (unsigned char) 0);

    /* Add general transaction functions to the record */
    do {
        pinFunc = (PFI) & srTransactionGeneralFuncs[inCount].pinFunction;
        if (shVarAddField(gpsrFunctionRecord, srTransactionGeneralFuncs[inCount].inFieldID, (unsigned char *) pinFunc, INT_POINTER_SIZE) != VAR_NO_ERROR)
            return (VS_ERR);
        inCount++;
    } while (srTransactionGeneralFuncs[inCount].inFieldID != END_OF_FUNC_TABLE);

    /* Add general operation functions to the record */
    inCount = 0;
    do {
        pinFunc = (PFI) & srOperationGeneralFuncs[inCount].pinFunction;
        if (shVarAddField(gpsrFunctionRecord, srOperationGeneralFuncs[inCount].inFieldID, (unsigned char *) pinFunc, INT_POINTER_SIZE) != VAR_NO_ERROR)
            return (VS_ERR);
        inCount++;
    } while (srOperationGeneralFuncs[inCount].inFieldID != END_OF_FUNC_TABLE);

    /* Add validation functions to the record */
    inCount = 0;
    do {
        pinFunc = (PFI) & srValidationFuncs[inCount].pinFunction;
        if (shVarAddField(gpsrFunctionRecord, srValidationFuncs[inCount].inFieldID, (unsigned char *) pinFunc, INT_POINTER_SIZE) != VAR_NO_ERROR)
            return (VS_ERR);
        inCount++;
    } while (srValidationFuncs[inCount].inFieldID != END_OF_FUNC_TABLE);

    /* Add overload functions to the record */
    inCount = 0;
    do {
        pinFunc = (PFI) & srOverLoadFuncs[inCount].pinFunction;
        if (shVarAddField(gpsrFunctionRecord, srOverLoadFuncs[inCount].inFieldID, (unsigned char *) pinFunc, INT_POINTER_SIZE) != VAR_NO_ERROR)
            return (VS_ERR);
        inCount++;
    } while (srOverLoadFuncs[inCount].inFieldID != END_OF_FUNC_TABLE);

    /* Add message file names to the record */
    inCount = 0;
    do {
        if (shVarAddField(gpsrFunctionRecord, srMsgFileNameTable[inCount].inFieldID, (unsigned char *) srMsgFileNameTable[inCount].pszMsgFileName, strlen(srMsgFileNameTable[inCount].pszMsgFileName)) != VAR_NO_ERROR)
            return (VS_ERR);
        inCount++;
    } while (srMsgFileNameTable[inCount].inFieldID != END_OF_FUNC_TABLE);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int *| inGetFunctionPointer|
*       Reads through the fucntion flexi record to find the
*       function corresponding to the field ID
*
* @parm int |inFieldID |
*       Field ID for the requested function
*
* @rdesc return values.
* @flag int    |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

PFI inGetFunctionPointer(unsigned short  inFieldID) {
   
 //jrd one source
    #ifdef __arm
     unsigned short    usLength;
    #endif
    #ifdef _TARG_68000
     unsigned int    usLength;
    #endif	
    unsigned char   ucAttributes, ucType;
    PFS pinFunc;
    char szErrorMsg[MESSAGE_SIZE];

    if (shVarGetField(gpsrFunctionRecord, inFieldID, (unsigned char *) &pinFunc, INT_POINTER_SIZE, &usLength) != VAR_NO_ERROR) {
        memset(szErrorMsg, 0, sizeof(szErrorMsg));
        vdGetMessageFromFile(FUNCTION_NOT_FOUND_MSG16, szErrorMsg);
        sprintf(&szErrorMsg[strlen(szErrorMsg)], " %04x", inFieldID);
        vdDisplayErrorString(szErrorMsg);
        return (NULL_PFI);
    } else {
        if (shVarQueryField(gpsrFunctionRecord, inFieldID, &usLength, &ucType, &ucAttributes) != VAR_NO_ERROR) {
            memset(szErrorMsg, 0, sizeof(szErrorMsg));
            vdGetMessageFromFile(FUNCTION_NOT_FOUND_MSG16, szErrorMsg);
            sprintf(&szErrorMsg[strlen(szErrorMsg)], " %04x", inFieldID);
            vdDisplayErrorString(szErrorMsg);
            return (NULL_PFI);
        }
        if (ucAttributes == VAR_ATT_READ_ONLY)
            return(NO_ACCESS);
        return ((PFI) pinFunc);
    }
}


/*********************************************************************************************
* @func int *| inAddFunctionPointer|
*       Adds a function pointer to the function table flexi record
*
* @parm int | inFieldID |
*       Field ID for the added function
*
* @parm PFI| pvdFuncPtr |
*       Function Pointer
*
* @rdesc return values.
* @flag int    |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inAddFunctionPointer(unsigned short  inFieldID,PFI_TO pvdFuncPtr) {
    PFI pinFunc;

    pinFunc = (PFI) & pvdFuncPtr;
    if (shVarAddField(gpsrFunctionRecord, inFieldID, (unsigned char *) pinFunc, INT_POINTER_SIZE) != VAR_NO_ERROR)
        return(VS_ERR);
    else
        return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int *| inOverloadFieldID|
*       Changes the function pointer for a field ID in the function table flexi record
*
* @parm int | inFieldID |
*       Field ID for the function to be changed
*
* @parm PFI| pvdFuncPtr |
*       New function Pointer
*
* @rdesc return values.
* @flag int    |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inOverloadFieldID(unsigned short  inFieldID,PFI_TO pvdFuncPtr) {
    PFI pinFunc;

    pinFunc = (PFI) & pvdFuncPtr;
    if (shVarUpdateField(gpsrFunctionRecord, inFieldID, (unsigned char *) pinFunc, INT_POINTER_SIZE) != VAR_NO_ERROR)
        return(VS_ERR);
    else
        return(VS_SUCCESS);
}



/*********************************************************************************************
* @func int | inGetMessageFileName|
*       Reads through the function flexi record to find the
*       message corresponding to the field ID
*
* @parm int |inFieldID |
*       Field ID for the requested function
*
* @rdesc return values.
* @flag int    |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inGetMessageFileName(short  inFieldID,char* pszNameBuffer) {
   //jrd one source
    #ifdef __arm
     unsigned short    usLength;
    #endif
    #ifdef _TARG_68000
     unsigned int    usLength;
    #endif	
    unsigned char   ucAttributes, ucType;
    char szErrorMsg[MESSAGE_SIZE];

    if (shVarGetField(gpsrFunctionRecord, inFieldID, (unsigned char *) pszNameBuffer, MSG_FILE_NAME_SIZE, &usLength) != VAR_NO_ERROR) {
        memset(szErrorMsg, 0, sizeof(szErrorMsg));
        vdGetMessageFromFile(FILE_ID_NOT_FOUND_MSG16, szErrorMsg);
        sprintf(&szErrorMsg[strlen(szErrorMsg)], " %04x", inFieldID);
        vdDisplayErrorString(szErrorMsg);
        return (VS_ERR);
    } else {
        if (shVarQueryField(gpsrFunctionRecord, inFieldID, &usLength, &ucType, &ucAttributes) != VAR_NO_ERROR) {
            memset(szErrorMsg, 0, sizeof(szErrorMsg));
            vdGetMessageFromFile(FILE_ID_NOT_FOUND_MSG16, szErrorMsg);
            sprintf(&szErrorMsg[strlen(szErrorMsg)], " %04x", inFieldID);
            vdDisplayErrorString(szErrorMsg);
            return (VS_ERR);
        }
        if (ucAttributes == VAR_ATT_READ_ONLY)
            return(VS_TRUE);
        return (VS_SUCCESS);
    }
}




/*********************************************************************************************
* @func int *| inAddMessageFileName|
*       Adds a message file name to the function table flexi record
*
* @parm int | inFieldID |
*       Field ID for the added file name
*
* @parm char *| pchMsgFileName |
*       Message file name
*
* @rdesc return values.
* @flag int    |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inAddMessageFileName(short  inFieldID,char* pchMsgFileName) {
    if (shVarAddField(gpsrFunctionRecord, inFieldID, (unsigned char *) pchMsgFileName, strlen(pchMsgFileName)) != VAR_NO_ERROR)
        return(VS_ERR);
    else
        return(VS_SUCCESS);
}

#undef VSTABLE_C
